const http = require('http');
const fs = require('fs');
const path = require('path');
const mime = require('mime');
http.createServer((req,res)=>{
    // console.log(req.url);
    // res.end('test');
    const fileName = path.join(__dirname,req.url);
    
    // res.end('test 路径')
    res.setHeader('Content-Type',mime.getType(fileName));
    if(req.url == '/public/html/index.html'){
        fs.readFile(fileName,(err,data)=>{
            if(!err){
                res.end(data);
            }else{
                console.log(err);
            }
        })
    }else if(req.url == '/public/img/konglong.jpg'){
        fs.readFile(fileName,(err,data)=>{
            if(!err){
                // res.setHeader('Content-Type',mime.getType(fileName));
                res.end(data);
            }else{
                console.log(err);
            }
        })
    }
}).listen(9000,(err)=>{
    if(!err) console.log('服务器启动成功');
    else console.log(err);
})
//5000 8080 8081 9000 9001 9002
